package com.dixon.worddayday.util;

import org.springframework.util.StringUtils;

import java.util.Arrays;

/**
 * @author dixon
 * @version 1.0.0
 * @Description 艾宾浩斯遗忘曲线 1,2,4,7,15,30
 * @createTime 2023年04月29日 20:56:00
 */
public class EbbinghausCurve implements IForgettingCurve{
    private int[] intervals = new int[] {1,2,4,7,15,30};
    private int totalReviewTimes;

    public EbbinghausCurve() {
    }

    public EbbinghausCurve(String intervalsStr) {
        if(!StringUtils.isEmpty(intervalsStr)) {
            this.intervals = Arrays.stream(intervalsStr.split(",")).mapToInt(Integer::parseInt).toArray();
        }

        this.totalReviewTimes = this.intervals.length+1;
    }

    @Override
    public int getNextDay(int reviewTimes) {
        if(reviewTimes < 1) {
            reviewTimes = 1;
        }
        else if (reviewTimes > this.intervals.length) {
            return 0;
        }

        return this.intervals[reviewTimes-1];
    }

    @Override
    public boolean isDone(int reviewTimes) {
        return reviewTimes>= this.totalReviewTimes;
    }

    @Override
    public int getTotalReviewTimes() {
        return this.totalReviewTimes;
    }

    public static void main(String[] args) {
        IForgettingCurve curve = new EbbinghausCurve();

        System.out.println(curve.getNextDay(0));
        System.out.println(curve.getNextDay(2));
        System.out.println(curve.getNextDay(5));
        System.out.println(curve.getNextDay(6));
    }
}
